const express = require('express')
const path = require('path')
const fs =require('fs')
const template = require('art-template')

const app = express()

app.engine('art',require('express-art-template'))
app.set('view options',{
    debug: process.env.NODE_ENV !== 'production'
})
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'art');
app.use(express.static(path.join(__dirname,'public')))
app.use(express.json())


app.get('/',(req,res)=>{
    res.render('index',{
        year:1000,
        className:'home',
        path:'/'
    })
})

const getFilePath = (path)=>path.match(/\/views\/(.*)\.html/i)[1]


app.get(/^\/views\/.*\.html$/i,(req,res)=>{
    console.log(req.path);
    console.log(req.ip);
    const path = getFilePath(req.path)
    res.render(path,{
        path,
        className:path
    })
})





app.listen(3500,()=>{
    console.log('app listen localhost:3000');
})